package com.qqtech.qquan.user.dao;

import java.util.List;

import com.qqtech.qquan.user.model.UserBaseConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import com.qqtech.core.common.util.BeanUtil;
import com.qqtech.core.frame.dao.BaseDaoImpl;
import com.qqtech.qquan.user.model.UserBase;
import com.qqtech.qquan.user.model.UserBaseQuery;
import com.qqtech.qquan.user.model.UserBaseVo;

@Repository
public class UserBaseDaoImpl extends BaseDaoImpl<UserBase> implements UserBaseDao {
	public static final Logger log = LoggerFactory.getLogger(UserBaseDaoImpl.class);

	@Override
	public int queryCountByIdentity(UserBase query) {
		return sqlSessionTemplate.selectOne(getSqlName("selectCountByIdentity"), BeanUtil.toMap(query));
	}

	@Override
	public Page<UserBaseVo> queryPageListByIdentity(UserBase query,
			Pageable pageable) {
		List<UserBaseVo> contentList = sqlSessionTemplate.selectList(getSqlName("selectByIdentity"), getParams(query, pageable));
		return new PageImpl<UserBaseVo>(contentList, pageable, this.queryCountByIdentity(query));
	}

	@Override
	public Page<UserBaseVo> queryPageList4Admin(UserBaseQuery query, Pageable pageable) {
		List<UserBaseVo> contentList = sqlSessionTemplate.selectList(getSqlName("select4Admin"), getParams(query, pageable));
		return new PageImpl<UserBaseVo>(contentList, pageable, this.queryCount4Admin(query));
	}

	@Override
	public int queryCount4Admin(UserBaseQuery query) {
		return sqlSessionTemplate.selectOne(getSqlName("selectCount4Admin"), BeanUtil.toMap(query));
	}
	
	@Override
	public List<UserBaseVo> queryList4Admin(UserBaseQuery query, Pageable pageable) {
		return sqlSessionTemplate.selectList(getSqlName("select4Admin"), getParams(query, pageable));
	}

	@Override
	public Page<UserBaseVo> queryPageListJoinCommunity(UserBaseQuery query, Pageable pageable) {
		List<UserBaseVo> contentList = sqlSessionTemplate.selectList(getSqlName("selectByJoinCommunity"), getParams(query, pageable));
		return new PageImpl<UserBaseVo>(contentList, pageable, this.queryCountJoinCommunity(query));
	}

	@Override
	public int queryCountJoinCommunity(UserBaseQuery query) {
		return sqlSessionTemplate.selectOne(getSqlName("selectCountByJoinCommunity"), BeanUtil.toMap(query));
	}

	@Override
	public Page<UserBaseVo> queryPageNeighbor(UserBaseQuery query, Pageable pageable) {
		List<UserBaseVo> contentList = sqlSessionTemplate.selectList(getSqlName("selectByNeighbor"), getParams(query, pageable));
		return new PageImpl<UserBaseVo>(contentList, pageable, this.queryCountNeighbor(query));
	}
	@Override
	public int queryCountNeighbor(UserBaseQuery query) {
		return sqlSessionTemplate.selectOne(getSqlName("selectCountByNeighbor"), BeanUtil.toMap(query));
	}
	@Override
	public int queryCountIsNew(UserBaseQuery query) {
		return sqlSessionTemplate.selectOne(getSqlName("selectCountByIsNew"), BeanUtil.toMap(query));
	}

	@Override
	public int queryCountIsNewByCommunityId(UserBaseQuery query) {
		return sqlSessionTemplate.selectOne(getSqlName("selectIsNewCountByCommunityId"), BeanUtil.toMap(query));
	}

	@Override
	public List<UserBaseConfig> queryUserConfigProfession() {
		return  sqlSessionTemplate.selectList(getSqlName("selectUserConfigProfession"));
	}

	@Override
	public List<UserBaseConfig> queryUserConfigHobby() {
		return sqlSessionTemplate.selectList(getSqlName("selectUserConfigHobby"));
	}

	@Override
	public List<UserBaseConfig> queryUserConfigDelicacy() {
		return sqlSessionTemplate.selectList(getSqlName("selectUserConfigDelicacy"));
	}

	public List<UserBaseConfig> queryUserConfigHometown() {
		return sqlSessionTemplate.selectList(getSqlName("selectUserConfigHometown"));
	}

	public List<UserBaseConfig> queryUserConfigEntertainment() {
		return sqlSessionTemplate.selectList(getSqlName("selectUserConfigEntertainment"));
	}
}
